#ifndef __C328R_H__
#define __C328R_H__


#ifndef C328R_DEF_PACKAGE_SIZE
#define C328R_DEF_PACKAGE_SIZE 64
#endif

#ifdef C328R_BAUD
#define SERIAL1_BAUD C328R_BAUD
#endif


/* include external library */
#include <serial1/serial1.h>


enum c328r_param_enums {
	
	C328R_COLOR_2BIT_GRAY = 0x01,
	C328R_COLOR_4BIT_GRAY,
	C328R_COLOR_8BIT_GRAY,
	
	C328R_COLOR_12BIT = 0x05,
	C328R_COLOR_16BIT,
	C328R_COLOR_JPEG,
	
	C328R_RES_80X60 = 0x01,
	C328R_RES_160X128 = 0x03,
	C328R_RES_320X240 = 0x05,
	C328R_RES_640X480 = 0x07,
	
	C328R_PIC_SNAP = 0x01,
	C328R_PIC_PREV,
	
	C328R_PIC_JPEG = 0x05,
	
	C328R_SNAP_COMP = 0,
	C328R_SNAP_UNCOMP,
};


typedef struct {
	uint8_t delimiter;
	uint8_t id;
	uint8_t param[4];
} c328r_command_t;


typedef struct {
	uint8_t id;
	uint8_t len[2];
	uint8_t data[C328R_DEF_PACKAGE_SIZE - 6];
	uint8_t chksum[2];
} c328r_packet_t;


typedef union {
	c328r_command_t cmd;
	c328r_packet_t pkt;
} c328r_t;


void C328R_init(void);

error_t C328R_start(uint8_t color, uint8_t res);

void C328R_reg(void (*startdone)(error_t), void (*getdone)(error_t, uint32_t),
               void (*receive)(void));

error_t C328R_getPicture(uint8_t type, uint8_t* buff);


#endif // __C328R_H__
